home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / appsource.lha / APlusPlus / TESTPRGS / intuition / SimpleWindow_test.cxx < prev   
Encoding:
C/C++ Source or Header  |  1994-08-29  |  3.8 KB  |  143 lines

  1. /******************************************************************************
  2.  *
  3.  *    $Source: apphome:RCS/testprgs/intuition/SimpleWindow_test.cxx,v $
  4.  *
  5.  *    Demo for the A++ Library
  6.  *    Copyright (C) 1994 by Armin Vogt, EMail: armin@uni-paderborn.de
  7.  *
  8.  *    $Revision: 1.8 $
  9.  *    $Date: 1994/07/23 19:15:49 $
  10.  *    $Author: Armin_Vogt $
  11.  *
  12.  ******************************************************************************/
  13.  
  14.  
  15. #include <APlusPlus/exec/SignalResponder.h>
  16. #include <APlusPlus/intuition/GWindow.h>
  17. #include <APlusPlus/intuition/IntuiMessageC.h>
  18. #include <APlusPlus/intuition/ScreenC.h>
  19.  
  20.  
  21. extern "C" {
  22. #include <dos/dos.h>
  23. }
  24.  
  25.  
  26. static const char rcs_id[]="$Id: SimpleWindow_test.cxx,v 1.8 1994/07/23 19:15:49 Armin_Vogt Exp Armin_Vogt $";
  27.  
  28.  
  29. // a CTRL-C signal responder from the example in the docs
  30. class MySRSP : public SignalResponder
  31. {
  32.    private:
  33.       BOOL running;  // indicates a received user break to object users
  34.    public:
  35.       MySRSP() : SignalResponder(SIGBREAKB_CTRL_C,0)
  36.       { running = TRUE; }
  37.       ~MySRSP() {}
  38.  
  39.       //  overload the virtual 'signal received' action callback method.
  40.       void actionCallback()
  41.       {
  42.          running = FALSE;  // end WaitSignal loop
  43.       }
  44.  
  45.       // object users can check with this method if a user break has occurred
  46.       BOOL hasNotOccured() { return running==TRUE; }
  47. };
  48.  
  49.  
  50.  
  51. class MyWindow : public GWindow
  52. {
  53.    public:
  54.       MyWindow(OWNER,AttrList& attrs) : GWindow(owner,attrs)
  55.       {
  56.          modifyIDCMP(CLASS_NEWSIZE|CLASS_CLOSEWINDOW|CLASS_ACTIVEWINDOW|CLASS_NEWSIZE);
  57.       }
  58.  
  59.       void On_CLOSEWINDOW(const IntuiMessageC* msg);
  60.       void On_ACTIVEWINDOW(const IntuiMessageC* msg);
  61.       void On_NEWSIZE(const IntuiMessageC* msg);
  62.  
  63.       void putText(const char* string);
  64.  
  65.       void handleIntuiMsg(const IntuiMessageC* imsg);
  66.  
  67.       // runtime type inquiry support
  68.       static const Intui_Type_info info_obj;
  69.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  70.          { return info_obj; }
  71.       static const Type_info& info()                // get the 'type_id' of a specific class
  72.          { return info_obj; }
  73.  
  74. };
  75.  
  76. intui_typeinfo(MyWindow, derived(from(GWindow)), rcs_id);
  77.  
  78.  
  79. void MyWindow::On_CLOSEWINDOW(const IntuiMessageC* msg)
  80.       {
  81.          putText("CLOSEWINDOW.");
  82.          delete this;   // it is allowed for WindowCV class to destroy itself
  83.       }
  84. void MyWindow::On_ACTIVEWINDOW(const IntuiMessageC* msg)
  85.       {
  86.          ULONG dummy=0;
  87.          char* e[40];
  88.          sprintf((char*)e,"%s is ACTIVE.",(char*)getAttribute(WA_Title,dummy));
  89.          putText((char*)e);
  90.       }
  91. void MyWindow::On_NEWSIZE(const IntuiMessageC* msg)
  92.       {         
  93.          adjustStdClip(); 
  94.          setStdClip();
  95.          putText("NEWSIZE. ");
  96.       }
  97. void MyWindow::handleIntuiMsg(const IntuiMessageC* imsg)
  98.       {
  99.          switch (imsg->getClass())
  100.          {
  101.             case CLASS_CLOSEWINDOW :
  102.                On_CLOSEWINDOW(imsg); break;
  103.             case CLASS_ACTIVEWINDOW :
  104.                On_ACTIVEWINDOW(imsg); break;
  105.             case CLASS_NEWSIZE :
  106.                On_NEWSIZE(imsg); break;
  107.          }
  108.          GWindow::handleIntuiMsg(imsg);
  109. }
  110.  
  111. void MyWindow::putText(const char* string)
  112. {
  113.    moveTx(0,0);
  114.    setDrMd(JAM2);
  115.    setAPen(1);
  116.    setBPen(0);
  117.    text((UBYTE*)string);
  118. }
  119.  
  120. void APPmain(int argc,char* argv[])
  121. {
  122.    MySRSP userBreak;
  123.  
  124.    ScreenC* screen  = new ScreenC(OWNER_NULL, AttrList(TAG_END) );
  125.    
  126.    MyWindow* little = new MyWindow(screen,
  127.    AttrList(
  128.       WA_Title,"WindowC - close this to stop.",
  129.       WA_Width,300,
  130.       WA_Height,150,
  131.       WA_MinHeight,50,
  132.       WA_MinWidth,80,
  133.       TAG_END) );
  134.  
  135.    little->putText("Welcome!");
  136.  
  137.    while (userBreak.hasNotOccured() && APPOK(little))
  138.       // APPOK(little) expands to (little!=NULL && little->Ok())
  139.    {
  140.       SignalResponder::WaitSignal();
  141.    }
  142. }
  143.